package org.example.smartbuy.controller;

import org.example.smartbuy.Result;
import org.example.smartbuy.entity.Productactions;
import org.example.smartbuy.service.IProductactionsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/productactions")
@Tag(name = "ProductActions Controller", description = "Operations related to product actions")
public class ProductactionsController {

    @Autowired
    private IProductactionsService productactionsService;

    /**
     * 获取所有产品动作记录
     * @return List<Productactions>
     */
    @GetMapping("/list")
    @Operation(summary = "Get all product action records", description = "Fetch a list of all product action records",
            responses = {
                    @ApiResponse(responseCode = "200", description = "操作成功"),
                    @ApiResponse(responseCode = "400", description = "操作失败")
            })
    public Result listAllProductActions() {
        return Result.success(productactionsService.listAll());
    }

    /**
     * 添加产品动作记录
     * @param productactions 产品动作记录对象
     * @return Productactions
     */
    @PostMapping("/add")
    @Operation(summary = "Add a new product action record", description = "Create a new product action record",
            responses = {
                    @ApiResponse(responseCode = "200", description = "操作成功"),
                    @ApiResponse(responseCode = "400", description = "操作失败")
            })
    public Result addProductAction(@RequestBody Productactions productactions) {
        return Result.success(productactionsService.add(productactions));
    }

    /**
     * 删除产品动作记录
     * @param id 产品动作记录ID
     */
    @DeleteMapping("/delete/{id}")
    @Operation(summary = "Delete a product action record", description = "Delete a product action record by its ID",
            responses = {
                    @ApiResponse(responseCode = "200", description = "操作成功"),
                    @ApiResponse(responseCode = "400", description = "操作失败")
            })
    public Result deleteProductAction(@PathVariable int id) {
        productactionsService.delete(id);
        return Result.success();
    }
}
